package com.exam.scjp5.objectives.section_1;

import java.util.NavigableMap;

public class ExampleCasting
{
	
    public static void main(String args[])
    {
        ParentCast p = new ParentCast();
        // Cannot cast ParentCast to ChildCast because 'p' refer to the instance of ParentCast
        // Not the instance of ChildCast
        //ChildCast c = (ChildCast) p; 
        
        ChildCast c = new ChildCast();
        // ChildCast is parent of SubChildCast.
        // You cannot cast parent class object to become child class object.
        SubChildCast c2 = (SubChildCast) c; 
        //p2 = (ParentCast) c2;
       
        c.method();
        c2 = (ChildCast2) p;
      
    }	
}

class ParentCast 
{
	void method()
	{
		System.out.println("Parent's method()");
	}
}
class ChildCast extends ParentCast 
{
	void method()
	{
		System.out.println("Child's method()");
	}
}

class SubChildCast extends ChildCast
{
	void method()
	{
		System.out.println("Child2's method()");
	}
}